package com.example.demo.Controller;

import com.example.demo.DAO.ShopDAO;
import com.example.demo.DAO.UserDAO;
import com.example.demo.DO.ShopDO;
import com.example.demo.DO.UserDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class ShopC {
    @Autowired
    ShopDAO shopDAO;
    @Autowired
    UserDAO userDAO;

    @RequestMapping("/manage_add")
    public String manage_add(HttpServletRequest request,ShopDO shopDO,Model model){
        String user=request.getParameter("name");
        model.addAttribute("name",user);
        String aucId=shopDO.getAucId();
        String gostart=shopDO.getGostart();
        String goend=shopDO.getGoend();
        Double aucPrice=shopDO.getAucPrice();
//        System.out.println(aucId);
//        System.out.println(gostart);
//        System.out.println(goend);
//        System.out.println(aucPrice);
        if (shopDAO.selectId(aucId).size()==0&&aucId!=null){
            shopDAO.insert(aucId,gostart,goend,aucPrice);
            model.addAttribute("shop_list",shopDAO.selectAll());
            return "manage_shop";
        }
        return "manage_ad";
    }
    @RequestMapping("/manage_del")
    public String manage_del(HttpServletRequest request,Model model){
        String aucId=request.getParameter("aucId");
        shopDAO.delete(aucId);
        model.addAttribute("shop_list",shopDAO.selectAll());
        return "manage_shop";
    }

    @RequestMapping("manage_user")
    public String manage_user(HttpServletRequest request,Model model){
        model.addAttribute("ex_user",userDAO.selectAll());
        return "manage_user";
    }
    @RequestMapping("manage_udel")
    public String manage_udel(HttpServletRequest request,Model model){
        String user=request.getParameter("user");
        userDAO.delete(user);
        model.addAttribute("ex_user",userDAO.selectAll());
        return "manage_user";
    }
}
